package org.wheel.module.core.exception;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import org.wheel.module.core.enm.NormalExceptionEnum;

public interface CustomAssert {
    
    /**
     * 判断对象非空
     * @param o 判断对象
     */
    default void assertNotNull(Object o) {
        if (o == null) {
            throw new NormalException(NormalExceptionEnum.EMPTY);
        }else if(o instanceof String) {
            if(StrUtil.isBlank(o.toString())) {
                throw new NormalException(NormalExceptionEnum.EMPTY);
            }
        } else if(ObjectUtil.isNull(o)) {
            throw new NormalException(NormalExceptionEnum.EMPTY);
        }else if(ObjectUtil.isEmpty(o)) {
            throw new NormalException(NormalExceptionEnum.EMPTY);
        }
    }
    
    /**
     * 判断对象非空
     * @param o 判断对象
     * @param args 异常信息
     */
    default void assertNotNull(Object o, ServiceExceptionEnum args) {
        if (o == null) {
            throw new NormalException(args);
        }else if(ObjectUtil.isNull(o)){
            throw new NormalException(args);
        } else if(ObjectUtil.isEmpty(o)) {
            throw new NormalException(args);
        } else if(o instanceof String) {
            if(StrUtil.isBlank(o.toString())) {
                throw new NormalException(args);
            }
        }
    }
}
